<template>
  <div>
    <!--      搜索组件-->
    <div style="display: flex;align-items: center;">
      <SearchModle dataKey="applyMateriel" @searchFn="searchFn" ref="searchModleFn"></SearchModle>
      <div style="width: 10px;"></div>
      <downexcel type="materielLendingEnd" :option="dowloadOption"></downexcel>
    </div>
    <!--本体列表，数据 -->
    <div class="table-body">
      <div class="table-body-box">
        <el-table
            ref="multipleTable"
            :data="arryList"
            :stripe="tableStripe"
            :border="tableBorder"
            tooltip-effect="dark"
            style="width: 100%"
            header-cell-class-name="table-text-c"
            cell-class-name="table-text-c">
          <el-table-column
              label="物料名称">
            <template slot-scope="scope">
              {{ scope.row.materiel.name }}
            </template>
          </el-table-column>
          <el-table-column
              label="领用人"
          width="110">
            <template slot-scope="scope">
              {{ scope.row.user.realname }}
            </template>
          </el-table-column>
          <el-table-column
              :key="4"
              label="领用数量"
              width="140">
            <template slot-scope="scope">
              {{scope.row.number}}{{ scope.row.materiel ? ' / '+ scope.row.materiel.unit : '' }}
            </template>
          </el-table-column>
          <el-table-column
              prop="create_time"
              label="申请时间"
              width="110">
          </el-table-column>
          <el-table-column
              prop="examine_time"
              label="领取时间"
              :key="1"
              width="110">
          </el-table-column>
          <el-table-column
              :key="3"
              label="领用状态"
              width="80">
            <template slot-scope="scope">
              已领取
            </template>
          </el-table-column>
          <el-table-column
              prop="content"
              label="申请用途">
          </el-table-column>
        </el-table>
      </div>
    </div>
    <!--工具条 分页-->
    <el-col :span="24" class="toolbar">
      <el-pagination
          background
          layout="total, prev, pager, next"
          :total="page.total"
          :page-size="page.pagesize"
          @current-change="handleSizeChange">
      </el-pagination>
    </el-col>
  </div>
</template>

<script>
import {pagination} from '@/utils/util.js'
import api from '@/utils/api.js'

export default {
  data() {
    return {
      tableStripe: true, // 是否斑马栏
      tableBorder: true, // 单元格右边边框
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      arryList: [], // 数据列表
      // 搜索
      searchForm: {},
      dowloadOption:{
        status:1
      }
    }
  },
  created() {
    this.InitFn()
  },
  methods: {
    async InitFn() {
      // types 	整型 	必填 	1 	- 	0进货1申请
      // type 0时间 1数量正序 2数量倒叙
      // status 	整型 	必填 	1 	- 	类型0申请1确认2取消
      this.searchForm.p = this.page.pageindex
      this.searchForm.types = 1
      this.searchForm.type = 0
      this.searchForm.status = 1
      let data = await this.$fetch(this.api.admin_materiel_log_index, this.searchForm)
      if (!data.code) {
        for (let i in data.list.data) {
          data.list.data[i].create_time = data.list.data[i].create_time.split(' ')[0]
          data.list.data[i].examine_time = data.list.data[i].examine_time.split(' ')[0]
        }
        this.tabTotal = data.number
        this.arryList = data.list.data
        this.page.total = data.list.total
        this.$emit('getNewNumber', data.number)
      } else {
      }
    },
    searchFn(option) {
      this.page.pageindex = 1;
      this.searchForm = option;
      this.dowloadOption= option; //status  0申请中1已领用
      this.dowloadOption.status = 1;
      this.InitFn()
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
  },
  mounted() {
  }
}
</script>

